<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>插入排序</title>
</head>
<body>
<script>
    var arr=[8,2,3,7,1,5,9,4,6,0,8,2,3,7,1,5,9,4,6,0,8];
    function insert(arr){
        var list=arr.splice(0,1);
        for(var i= 0,j=arr.length;i<j;i++){
            var length=list.length;
            while(length--){
                if(arr[i]>=list[length]){
                    list.splice(length+1,0,arr[i]);
                    break;
                }
                if(0==length)list.unshift(arr[i]);
            }
        }
        return list;
    }

    console.log(insert(arr));
</script>
</body>
</html>